#ifndef _UTILEX_AUTOLOCK_HPP_
#define _UTILEX_AUTOLOCK_HPP_

#include <crt_util.h>

#ifdef __cplusplus

class CAutoLock
{
public:
    void Lock()
    {
        // TODO==>problem
        _mutex_lock(&lock);
    }

    void UnLock() { _mutex_unlock(&lock); }

    CAutoLock() { _mutex_init(&lock); }

    virtual ~CAutoLock() { _mutex_destroy(&lock); }

private:
    _mutex_t lock;
};

template <class T> class CStackLockWrapper2
{
public:
    CStackLockWrapper2(T* _t) : t(_t) { t->Lock(); }
    ~CStackLockWrapper2() { t->UnLock(); }
    T* t;
};

typedef CStackLockWrapper2<CAutoLock> CStackAutoCSLock;

#define SYNC_OBJ(x) CStackAutoCSLock lock(x);

#endif

#endif
